package main
import (
	"fmt"
	"encoding/json"
	"os"
)

type student struct{
	Id int	`json:"id"`
	Name string	`json:"name"`
	Sex byte	`json:"sex"`
	Age int	`json:"age"`
	Chengji []float64	`json:"chengji"`
}

func main(){
	var st student = student{20180819001, "瑞哥", 'G', 22, []float64{95.0, 96.0, 97.0, 98.0} }
	f, err := os.Create("./测试.json")
	if err != nil{
		fmt.Println("err = ", err)
		return
	}
	defer f.Close()
	buf, err2 := json.MarshalIndent(st, "", " ")
	if err2 != nil{
		fmt.Println("err2 = ", err2)
	}
	num, err3 := f.Write(buf)
	if err3 != nil{
		fmt.Println("err3 = ", err3)
	}else{
		fmt.Println("写入成功，共", num, "个字节")
	}
}
